package cn.seaboot.admin.core.web;

import cn.seaboot.admin.core.bean.DynamicDictionary;
import cn.seaboot.admin.core.service.DynamicDictionaryService;
import cn.seaboot.admin.mvc.Pagination;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 动态字典配置 [t_sys_dynamic_dictionary] - Controller
 *
 * @author Mr.css on 2018-6-20
 * @version 1.0.0
 */
@Controller
@RequestMapping("sys/dynamic/dic")
@Tag(name = "动态字典配置 [t_sys_dynamic_dictionary] 管理")
public class DynamicDictionaryCtrl {

    @Resource
    private DynamicDictionaryService dynamicDicService;

    /**
     * 查列表
     *
     * @return PageInfo
     */
    @ResponseBody
    @Operation(description = "动态字典配置 [t_sys_dynamic_dictionary] 列表查询")
    @Parameters({
            @Parameter(name = "page", description = "页号"),
            @Parameter(name = "limit", description = "行数")})
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public PageInfo<DynamicDictionary> queryPage(HttpServletRequest request) {
        return Pagination.get(request, dynamicDicService::selectAll);
    }

    /**
     * 更新系统参数
     *
     * @param id     ID
     * @param dicVal 值
     * @return 是否成功
     * @throws IOException       模版引擎渲染异常
     */
    @ResponseBody
    @Operation(description = "动态字典配置 [t_sys_dynamic_dictionary] 改")
    @Parameters({
            @Parameter(name = "id", description = "ID"),
            @Parameter(name = "dicVal", description = "值")
    })
    @RequestMapping(value = "info", method = RequestMethod.PUT)
    public int updateById(String id, String dicVal) throws IOException {
        return dynamicDicService.updateById(id, dicVal);
    }
}

//
//     /**
//      * 增
//      *
//      * @param dic pojo
//      * @return affected rows
//      */
//     @ResponseBody
//     @Operation(description = "动态字典配置 [t_sys_dynamic_dictionary] 增")
//     @RequestMapping(value = "info", method = RequestMethod.POST)
//     public int insert(@RequestParam Map<String, Object> dic) {
//         return dynamicDicService.insert(dic);
//     }
//
//     /**
//      * 查
//      *
//      * @param id id
//      * @return pojo
//      */
//     @ResponseBody
//     @Operation(description = "动态字典配置 [t_sys_dynamic_dictionary] 查")
//     @RequestMapping(value = "info", method = RequestMethod.GET)
//     public Map<String, Object> selectById(@Params String id) {
//         return dynamicDicService.selectById(id);
//     }
//
//     /**
//      * 删
//      *
//      * @param id id
//      * @return affected rows
//      */
//     @ResponseBody
//     @Operation(description = "动态字典配置 [t_sys_dynamic_dictionary] 删")
//     @RequestMapping(value = "info", method = RequestMethod.DELETE)
//     public int deleteById(@Params String id) {
//         return dynamicDicService.deleteById(id);
//     }
//
//     /**
//      * 查
//      *
//      * @param sort 字典名称
//      * @return pojo
//      */
//     @ResponseBody
//     @Operation(description = "动态字典配置 [t_sys_dynamic_dictionary] 查询数据字典")
//     @RequestMapping(value = "dic", method = RequestMethod.GET)
//     public List<Dictionary> queryByType(@Params String sort) {
//         return dynamicDicService.queryBySort(sort);
//     }
